libobs_sources\windows\sources/
game_capture.rs1use libobs_window_helper::{get_all_windows, WindowInfo, WindowSearchMode};
2use libobs_wrapper::{data::StringEnum, sources::ObsSourceRef};
3
4use crate::macro_helper::define_object_manager;
5
6use super::{ObsHookRate, ObsWindowPriority};
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum ObsGameCaptureMode {
11 Any,
13 CaptureSpecificWindow,
15 CaptureForegroundWindow,
17}
18
19#[derive(Clone, Copy, Debug, PartialEq, Eq)]
20pub enum ObsGameCaptureRgbaSpace {
21 SRgb,
23 RGBA2100pq,
25}
26
27impl StringEnum for ObsGameCaptureRgbaSpace {
28 fn to_str(&self) -> &str {
29 match self {
30 ObsGameCaptureRgbaSpace::SRgb => "sRGB",
31 ObsGameCaptureRgbaSpace::RGBA2100pq => "Rec. 2100 (PQ)",
32 }
33 }
34}
35
36impl StringEnum for ObsGameCaptureMode {
37 fn to_str(&self) -> &str {
38 match self {
39 ObsGameCaptureMode::Any => "any_fullscreen",
40 ObsGameCaptureMode::CaptureSpecificWindow => "window",
41 ObsGameCaptureMode::CaptureForegroundWindow => "hotkey",
42 }
43 }
44}
45
46define_object_manager!(
47 #[derive(Debug)]
48 struct GameCaptureSource("game_capture") for ObsSourceRef {
49 #[obs_property(type_t = "enum_string")]
51 capture_mode: ObsGameCaptureMode,
52
53 #[obs_property(type_t = "string", settings_key = "window")]
63 window_raw: String,
64
65 #[obs_property(type_t = "enum")]
66 priority: ObsWindowPriority,
68
69 #[obs_property(type_t = "bool")]
70 sli_compatability: bool,
72
73 #[obs_property(type_t = "bool")]
74 capture_cursor: bool,
76
77 #[obs_property(type_t = "bool")]
78 allow_transparency: bool,
80
81 #[obs_property(type_t = "bool")]
82 premultiplied_alpha: bool,
84
85 #[obs_property(type_t = "bool")]
87 limit_framerate: bool,
88
89 #[obs_property(type_t = "bool")]
91 capture_overlays: bool,
92
93 #[obs_property(type_t = "bool")]
95 anti_cheat_hook: bool,
96
97 #[obs_property(type_t = "enum")]
99 hook_rate: ObsHookRate,
100
101 #[obs_property(type_t = "enum_string")]
103 rgb10a2_space: ObsGameCaptureRgbaSpace,
104
105 #[obs_property(type_t = "bool")]
109 capture_audio: bool,
110 }
111);
112
113#[cfg(feature = "window-list")]
114impl GameCaptureSourceBuilder {
115 pub fn get_windows(mode: WindowSearchMode) -> anyhow::Result<Vec<WindowInfo>> {
117 get_all_windows(mode).map(|e| e.into_iter().filter(|x| x.is_game).collect::<Vec<_>>())
118 }
119
120 pub fn set_window(self, window: &WindowInfo) -> Self {
130 self.set_window_raw(window.obs_id.as_str())
131 }
132}